﻿using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using Rio.Framework.RioManager;
using NetBay.Core.DataAccess;

namespace Rio.Manager.DataAccess
{
    public static class DatabaseEx
    {
        private const string OracleString = "Oracle";

        /// <summary>
        /// Prepare and get new command
        /// </summary>
        /// <param name="db">Database instance</param>
        /// <param name="dbFunction">dbFunction to execute</param>
        /// <param name="AddOutputParameterWithOracle">The add output parameter with oracle.</param>
        /// <returns></returns>
        public static DbCommand GetNewCommand(this Database db, string dbFunction, bool AddOutputParameterWithOracle = true)
        {
            var l_bOutPutParameter = false;
            switch (SettingsManager.cStoreSettings.Parameter_EngineDataBase)
            {
                case OracleString:
                    l_bOutPutParameter = true;
                    break;
            }

            var dbCommand = db.GetStoredProcCommand(dbFunction);
            if (l_bOutPutParameter && AddOutputParameterWithOracle)
            {
                dbCommand.AddOracleResultParameter();
            }
            return dbCommand;
        }
    }
}